package com.hanbang.chu_xing_gao_zhao.view_me;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanbang.chu_xing_gao_zhao.activity.camera.CameraVideo;
import com.hanbang.chu_xing_gao_zhao.base.MainActivity;
import com.hanbang.chu_xing_gao_zhao.module.LogInActivity;
import com.hanbang.chu_xing_gao_zhao.utils.MyLog;
import com.hanbang.chu_xing_gao_zhao.utils.SystemTools;
import com.hanbang.cxgz_2.R;

/**
 * 我的主页
 */
public class MeActivity extends MainActivity {
    private LinearLayout me;
    /**
     * 肖像
     */
    private ImageView portrait;
    private LinearLayout orde;
    private LinearLayout frient;
    private LinearLayout invit;
    private LinearLayout group;
    private LinearLayout balance;
    private LinearLayout collect;
    private LinearLayout dynamic;
    private LinearLayout esoterica;
    private LinearLayout classroom;
    private LinearLayout data;
    private LinearLayout infor;
    private LinearLayout teacherStudent;
    private LinearLayout studio;
    private LinearLayout about;
    private LinearLayout explain;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.me_activity);

        initView();
        setOnClickListener();
        setUpViewsAndAddLinstener(me);
        addData();
    }


    /**
     * 初始化view
     */
    private void initView() {
        me = (LinearLayout) findViewById(R.id.bar_botton_bar_me);
        portrait = (ImageView) findViewById(R.id.me_activity_portrait);
        orde = (LinearLayout) findViewById(R.id.LL_me_orde);
        frient = (LinearLayout) findViewById(R.id.ll_me_friend);
        invit = (LinearLayout) findViewById(R.id.ll_me_invit);
        group = (LinearLayout) findViewById(R.id.ll_me_group);
        balance = (LinearLayout) findViewById(R.id.ll_me_balance);
        collect = (LinearLayout) findViewById(R.id.ll_me_collect);
        dynamic = (LinearLayout) findViewById(R.id.ll_me_dynamic);
        esoterica = (LinearLayout) findViewById(R.id.ll_me_esoterica);
        classroom = (LinearLayout) findViewById(R.id.ll_me_classroom);
        data = (LinearLayout) findViewById(R.id.ll_me_data);
        infor = (LinearLayout) findViewById(R.id.ll_me_infor);
        teacherStudent = (LinearLayout) findViewById(R.id.ll_me_techerStudent);
        studio = (LinearLayout) findViewById(R.id.ll_me_studio);
        about = (LinearLayout) findViewById(R.id.ll_me_about);
        explain = (LinearLayout) findViewById(R.id.ll_me_explain);
    }

    /**
     * 设置点击事件
     */
    private void setOnClickListener() {
        portrait.setOnClickListener(this);
        orde.setOnClickListener(this);
        frient.setOnClickListener(this);
        invit.setOnClickListener(this);
        group.setOnClickListener(this);
        balance.setOnClickListener(this);
        collect.setOnClickListener(this);
        dynamic.setOnClickListener(this);
        esoterica.setOnClickListener(this);
        classroom.setOnClickListener(this);
        data.setOnClickListener(this);
        infor.setOnClickListener(this);
        teacherStudent.setOnClickListener(this);
        studio.setOnClickListener(this);
        about.setOnClickListener(this);
        explain.setOnClickListener(this);

    }

    /**
     * 个人的信息赋值
     */
    private void addData() {
//        MyLog.e("text", "AAAAA" + userData.getAvatar() + "getCuisines_id" + userData.getCuisines_id() + "getCity_id" + userData.getCity_id());
        bitmapUtils.display(portrait, SystemTools.getHttpFileUrl(userData.getAvatar()));
        ((TextView) findViewById(R.id.me_activity_name)).setText(userData.getUser_name());
        ((TextView) findViewById(R.id.me_activity_shanChang)).setText("擅长：" + getCuisineName(userData.getCuisines_id()));
        ((TextView) findViewById(R.id.me_activity_location)).setText("居住地：" + getCity(userData.getCity_id()));
    }

    /**
     * 得以城市
     *
     * @param city
     * @return
     */
    private String getCity(int city) {
        for (int i = 0; i < cityDataList.size(); i++) {
            if (city == cityDataList.get(i).getCityID()) {
                return cityDataList.get(i).getCityName();
            }
        }

        return "";
    }

    /**
     * 得到菜系
     *
     * @param cuisine
     * @return
     */
    private String getCuisineName(String cuisine) {

        if (cuisine.substring(0, 1).equals(",")) {
            cuisine = cuisine.substring(cuisine.indexOf(",") + 1);
        }

        if (cuisine.substring(cuisine.length() - 1).equals(",")) {
            cuisine = cuisine.substring(0, cuisine.lastIndexOf(","));
        }

        String[] temp = cuisine.split(",");
        StringBuffer sb = new StringBuffer();

        //如果菜系集合是空则加载菜系
        if (styleOfCookingList.size() == 0) {
            getSytleOfCookingData();
        }


        for (int i = 0; i < temp.length; i++) {
            for (int j = 0; j < styleOfCookingList.size(); j++) {

                if (styleOfCookingList.get(j).getId() == Integer.parseInt(temp[i])) {
                    //如果是最后一个就不加“，”
                    if (i == temp.length - 1) {
                        sb.append(styleOfCookingList.get(j).getTitle());
                    } else {
                        sb.append(styleOfCookingList.get(j).getTitle() + ",");
                    }
                }
            }
        }

        return sb.toString();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == CameraVideo.FINSH_INTENT_FLAG && resultCode == CameraVideo.FINSH_INTENT_FLAG) {
            String filePath = data.getStringExtra("filePath");
            MyLog.e("sssssssss", filePath);
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.me_activity_portrait:
                intent.setClass(MeActivity.this, LogInActivity.class);
                startActivity(intent);
//
                break;
            case R.id.LL_me_orde:
                intent.setClass(MeActivity.this, MeOrdeActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_friend:
                intent.setClass(MeActivity.this, MeFriendActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_invit:
                intent.setClass(MeActivity.this, MeInvitActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_group:
                intent.setClass(MeActivity.this, MeGroupActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_balance:
                intent.setClass(MeActivity.this, MeBalanceActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_collect:
                intent.setClass(MeActivity.this, MeCollectFragmentActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_dynamic:
                intent.setClass(MeActivity.this, MeDynamicActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_esoterica:
                intent.setClass(MeActivity.this, MeEsotericaActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_classroom:
                intent.setClass(MeActivity.this, MeClassroomActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_data:
                intent.setClass(MeActivity.this, MeDataActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_infor:
                intent.setClass(MeActivity.this, MeInforActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_techerStudent:
                intent.setClass(MeActivity.this, MeTeacherStudentActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_studio:
                intent.setClass(MeActivity.this, MeStudioActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_about:
                intent.setClass(MeActivity.this, MeAboutActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_me_explain:
                intent.setClass(MeActivity.this, com.hanbang.chu_xing_gao_zhao.view_me.MeExplainActivity.class);
                startActivity(intent);
                break;

            default:
                break;
        }

    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        setTitleMore(View.GONE, View.GONE, "我", null, null, null);

        super.onResume();
    }

}
